<?php
namespace Modules\Activity\Http\Controllers\Client;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use \Modules\Activity\Entities\ActivityRecord;

use \Modules\User\Entities\User;

use Validator;
use ThrowException;
use DB;
use Auth;

// 活动参与记录(如果一个人多次参与同一个活动，则有多条记录)
class ActivityRecordController extends Controller
{
    public function index(Request $req)
    {
        $rule = [
            'status' => ['required']
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $options = $req->all();

        $user = Auth::requireLoginUser();

        $options['where'] = [
            'user_id' => $user->id
        ];
        $options['scopes']['status'] = $req->status;
        $options['with'] = ['activity'];

        $options['builder'] = ActivityRecord::distinct();

        $options['only'] = [
            'id',
            'uuid',
            'activity' => [
                'id',
                'uuid',
                'title',
                'sub_title',
                'thumb',
                'type',
                'type_text',
                'union_status',
                'union_status_text',
                'money_price',
                'score_price',
                'is_need_pay',
                'skus_count',
                'prize_total',
            ]
        ];

        $list = ActivityRecord::getList($options);

        return $list->generateListResponse();
    }
}
